//
//  RankingViewController.m
//  FootballSport
//
//  Created by lanou3g on 15/5/28.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//


#import "RankingViewController.h"
#import "SERIRankViewController.h"
@interface RankingViewController ()<UIScrollViewDelegate>

@end

@implementation RankingViewController
-(instancetype)init{
    if (self = [super init]) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(execute:) name:segmentSendNotification object:nil];
        
    }
    return self;
}

-(UIScrollView *)rankScrollV{
    if (_rankScrollV ==nil) {
     
        _rankScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds),CGRectGetHeight(self.view.bounds)-64-44)];
       
        _rankScrollV.contentSize = CGSizeMake(4*CGRectGetWidth(self.view.bounds), 0);
        _rankScrollV.pagingEnabled = YES;
    }
    return _rankScrollV;
}

- (void)viewDidLoad {
    [super viewDidLoad];
   self.navigationController.navigationBar.translucent = NO;
    [self.view addSubview: self.rankScrollV];
    

    self.rankScrollV.delegate =self;
    self.rankScrollV.contentOffset = CGPointMake(0, 0);
    
    self.rankVC=[[RankViewController alloc] init];
    [self addChildViewController:_rankVC];
    
    [self.rankScrollV addSubview:_rankVC.view];
    CBARankingViewController *CBArankVC=[[CBARankingViewController alloc] init];
    [self addChildViewController:CBArankVC];
    [self.rankScrollV addSubview:CBArankVC.view];
    CHLGRankingViewController *CHLGrankVC=[[CHLGRankingViewController alloc] init];
    [self addChildViewController:CHLGrankVC];
    [self.rankScrollV addSubview:CHLGrankVC.view];
    _rankScrollV.bounces = NO;

    
    SERIRankViewController *SERIRankVC=[[SERIRankViewController alloc] init];
    [self addChildViewController:SERIRankVC];
    [self.rankScrollV addSubview:SERIRankVC.view];

    
    
    
    
    
    
    // Do any additional setup after loading the view.
}
- (void)execute:(NSNotification*)notification{
    NSNumber *number = notification.object;
    self.rankScrollV.contentOffset = CGPointMake(CGRectGetWidth(self.view.bounds)*[number integerValue], 0);
    
    CGRect frame = self.rankScrollV.frame;
    frame.origin.y = 0;
    self.rankScrollV.frame = frame;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    NSNumber *number = [NSNumber numberWithInteger:(NSInteger)(self.rankScrollV.contentOffset.x/CGRectGetWidth(self.rankScrollV.frame))];
    [[NSNotificationCenter defaultCenter] postNotificationName:scrollSendNotification object:number];
    [[NSNotificationCenter defaultCenter] postNotificationName:segmentSendNotification object:number];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
